home *** CD-ROM | disk | FTP | other *** search
- Path: aixterm4.urz.uni-heidelberg.de!abangert
- From: abangert@aixterm4.urz.uni-heidelberg.de (Achim Bangert)
- Newsgroups: comp.lang.c
- Subject: Error in fp-exception handling?
- Date: 17 Mar 1996 02:06:09 GMT
- Organization: University of Heidelberg, Germany
- Message-ID: <4ifs2i$ld2@sun0.urz.uni-heidelberg.de>
- NNTP-Posting-Host: aixterm4.urz.uni-heidelberg.de
- Keywords: floating point exception
- X-Newsreader: TIN [version 1.2 PL2]
-
- Hello,
-
- I have a problem concerning the detection of floating point exceptions.
- Running the following program:
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <errno.h>
- #include <signal.h>
-
- void sighandler(int signo)
- {
- fprintf(stderr, "Catched signal no. %d: %s\n", signo, strsignal(signo));
- fprintf(stderr, "Error no. %d: %s\n", errno, strerror(errno));
- exit(1);
- }
-
- int main(void)
- {
- double a, b, c, d;
- double x, y, z;
- struct sigaction action;
-
- action.sa_handler = sighandler;
- sigemptyset(&action.sa_mask);
- action.sa_flags = 0;
- if(sigaction(SIGFPE, &action, NULL) < 0)
- exit(1);
- printf("Please input four double values:\n");
- scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
- errno = 0;
- x = a * b;
- printf("%16.11e * %16.11e = %16.11e error no. %d\n", a, b, x, errno);
- errno = 0;
- y = log(c);
- printf("ln(%16.11e) = %16.11e error no. %d\n", c, y, errno);
- errno = 0;
- z = exp(d);
- printf("exp(%16.11e) = %16.11e error no. %d\n", d, z, errno);
- exit(0);
- }
-
-
- I get some confusing results. For expample:
-
-
- Please input four double values:
- 1e100 2e250 3 4
- 1.00000000000e+100 * 2.00000000000e+250 = 3.59363441623e+77 error no. 0
- Catched signal no. 8: Floating point exception
- Error no. 2: No such file or directory
-
- (no detection of the overflow)
-
- Please input four double values:
- 1 2 3 1234
- 1.00000000000e+00 * 2.00000000000e+00 = 2.00000000000e+00 error no. 0
- ln(3.00000000000e+00) = 1.09861228867e+00 error no. 0
- exp(1.23400000000e+03) = -1.99808192253e+00 error no. 0
-
- (the same here, but not in the following example)
-
- Please input four double values:
- 1 2 3 12345
- 1.00000000000e+00 * 2.00000000000e+00 = 2.00000000000e+00 error no. 0
- ln(3.00000000000e+00) = 1.09861228867e+00 error no. 0
- Catched signal no. 8: Floating point exception
- Error no. 2: No such file or directory
-
-
- My computer has a pentium processor and is running under Linux 1.2.13.
- I have compiled this program with "gcc -o fptest fptest.c -lm" using
- gcc 2.7.0, libm 4.6.27
- Can anybody help me with this problem? Did I make something wrong or is the
- system to blame (hardware or software)? I asked some friends of mine to
- run this program and depending on processor type and kernel/compiler version
- they could reproduce this behaviour or not. Furthermore, in the info files to
- glibc (0.06 DRAFT) is mentioned that the library functions would not raise
- SIGFPE but set errno instead. Is this no longer valid?
-
- Hopefully somebody knows the answer to my question.
-
- Thanks,
- Achim Bangert
-
- --
- --------------------------------------------------------------
- Achim Bangert abangert@ix.urz.uni-heidelberg.de
-